var getCookie=readCookie("user")
if(!getCookie){
	location.href="login.htm"
}
var num=1
var count=0
var myFlag=""
var myFlag1=""
getUserInfo()
myVue()
getFromCount()
initData()
$(function(){
	setInterval("setTime()",1000)
})
myPage()
getFormState()
function myPage(){
	var page = new Pagin({
		el:"#page",	//绑定分页div
		dataSize:count,	//数据量
		pageSize:3	,//每页数量
		func:function(){
			
			num=PaginJson.pageIndex
			
			initData()
		}
	})
}
function myVue(){
	vm=new Vue({
		el:".user_info_p_s",
		data:{
			info:[]
			
		},
		methods:{
			deleteForm(id){
				myFlag=id
				$.DialogByZ.Confirm({Title: "", Content: "是否确定删除",FunL:confirmL,FunR:Immediate})
			
			},
			okForm(id){
				myFlag1=id
				$.DialogByZ.Confirm({Title: "", Content: "是否确定收货",FunL:confirmL1,FunR:Immediate})
				
			}
			}
		
	})
	

	
}
 function confirmL1(){
			$.DialogByZ.Close();
			okForm(myFlag1)
			
   }
 function confirmL(){
			$.DialogByZ.Close();
			deleteForm(myFlag)
			
   }
   function Immediate(){
   	  $.DialogByZ.Close();
      }
function okForm(id){
	$.ajax({
		url:"http://localhost:8080/OrderForm/updateDis",
		data:{"id":id,"dis":'3'},
		type:"post",
		dataType:"json",
		async:false,
		success:function(data){
				
			if(data.status==1){
			 initData()
			 getFormState()
			}else{
				
				$.DialogByZ.Alert({Title: "提示", Content: "服务器异常",BtnL:"确定"})
			}
		
		}
	})
	}
function deleteForm(id){
	$.ajax({
		url:"http://localhost:8080/OrderForm/updateDis",
		data:{"id":id,"dis":'0'},
		type:"post",
		dataType:"json",
		async:false,
		success:function(data){
				
			if(data.status==1){
			getFromCount()
			 initData()
			 
			 myPage()
			 getFormState()
			}else{
				$.DialogByZ.Alert({Title: "提示", Content: "服务器异常",BtnL:"确定"})
			}
		
		}
	})
	}
function initData(){
	 
	$.ajax({
		url:"http://localhost:8080/OrderForm/selectByForm",
		data:{"uId":getCookie,
		"pageNum":num,
		"pageSize":"3"},
		type:"get",
		dataType:"json",
		async:false,
		success:function(data){
			
			vm.$data.info=data.data.list
			
		
		}
	})
	
}

function getFromCount(){
	$.ajax({
		url:"http://localhost:8080/OrderForm/getFromCount",
		data:{"uId":getCookie},
		type:"get",
		dataType:"json",
		async:false,
		success:function(data){
			count=data.data
			$(".us_jls").html("共"+data.data+"条记录")
			
		
		}
	})
}
function getFormState(){
	var notOver=0
	var isOver=0
	var state=getDataNum()
	for(var i=0;i<state.length;i++){
		
		if(state[i].dis!=3){//未完成的订单
			notOver++
		}else if(state[i].dis==3){//已完成的订单
			isOver++
		}
	}
	
	$("#notOver").text(notOver)
	$("#isOver").text(isOver)
}

function getDataNum(){
	 var list=""
	$.ajax({
		url:"http://localhost:8080/OrderForm/selectByForm",
		data:{"uId":getCookie},
		type:"get",
		dataType:"json",
		async:false,
		success:function(data){
			
			list=data.data.list
			
		
		}
	})
	return list
}

function getUserInfo(){
	$.ajax({
		url:"http://localhost:8080/user/login",
		type:"post",
		dataType:"json",
		data:{
			"id":getCookie
			},
		async:false,
		success:function(data){
			$("#userName").html(data.data.uName)
		
		}
	})
}
function setTime(){
	var myDate=new Date().toLocaleString()
	$("#myTime").html(myDate)
	
}